(function ($) {
    $(function () {
        const observer = new MutationObserver((mutations) => {
            mutations.forEach(() => {
                // 移除复制按钮的提示文字
                $('.copybtn svg title').remove()
            });
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true  // 监控所有子节点变化
        });

        /**
        文章页脚内容为空时隐藏
         */
        function removeEmptyContentFooter() {
            const childrenLength = $('.bd-footer-content__inner.container').children().length;
            if (childrenLength === 0) {
                $('.bd-footer-content.noprint').hide();
            }
        }

        /**
        更新点击显示源代码链接的默认行为：在新窗口打开链接，防止跳转后页面被污染
         */
        function updateSourceLinkAction(){
            $('.tocsection.sourcelink a')
                .attr('target', '_blank')
                .attr('rel', 'noopener noreferrer');
        }

        updateSourceLinkAction();
        removeEmptyContentFooter();
    })
})(jQuery);